'''
Created on Aug 10, 2011

@author: mark
'''
import tkSimpleDialog
from Tkinter import Label, Entry, Checkbutton, IntVar, END

class BlockEditorDlg(tkSimpleDialog.Dialog):
    '''
    classdocs
    '''
    def __init__(self, parent, row, col, val, label_text="Letter Value:"):
        self.val = val
        self.label_text = label_text
        tkSimpleDialog.Dialog.__init__(self, parent, title='Edit block (%d, %d)' % (row+1, col+1))

    def body(self, master):
        Label(master, text=self.label_text).grid(row=0)

        self.e1 = Entry(master)
        self.e1.insert(0, self.val)
        self.e1.select_range(0, END)
        
        var = IntVar(value=1)
        self.cb1 = Checkbutton(master, text="Pre-existing", variable=var)
        self.cb1.var = var

        self.e1.grid(row=1, columnspan=2)
        self.cb1.grid(row=0, column=1)
        return self.e1 # initial focus

    def apply(self):
        self.letter = self.e1.get()[0:min(1, len(self.e1.get()))].strip().lower()
        self.val = self.e1.get()
        self.pre = self.cb1.var.get()
    